package top.caoayu.common.response;

import lombok.Builder;
import lombok.Data;
import top.caoayu.common.constant.ResponseBody;

import java.time.LocalDateTime;

@Builder
@Data
public class Result<T> {
    private LocalDateTime dateTime;
    private String code;
    private String message;
    public T data;

    public static <T> Result<T> success(T data) {
        return success(data, "ok");
    }

    public static <T> Result<T> success(T data, String message) {
        return Result.<T>builder()
                .dateTime(LocalDateTime.now())
                .code(ResponseBody.SUCCESS.getCode())
                .message(message)
                .data(data)
                .build();
    }

    public static <T> Result<T> fail(String message) {
        return fail(null, message);
    }

    public static <T> Result<T> fail(T data, String message) {
        return Result.<T>builder()
                .code(ResponseBody.FAIL.getCode())
                .message(message)
                .dateTime(LocalDateTime.now())
                .data(data)
                .build();
    }
}
